home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Gallery / Source / GalleryWindow.cpp next >
Encoding:
C/C++ Source or Header  |  1997-07-15  |  30.5 KB  |  1,018 lines

  1. #include <stream.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <stdio.h>
  6.  
  7. #include <clib/utility_protos.h>
  8.  
  9. #include "GUICINCLUDE:GUIC_Error.hpp"
  10. #include "GUICINCLUDE:GUIC_Message.hpp"
  11. #include "GUICINCLUDE:GUIC_System.hpp"
  12. #include "GUICINCLUDE:GUIC_DirectoryExamine.hpp"
  13. #include "GUICINCLUDE:GUIC_StringType.hpp"
  14. #include "GUICINCLUDE:GUIC_File.hpp"
  15. #include "GUICINCLUDE:GUIC_Exceptions.hpp"
  16. #include "GUICINCLUDE:GUIC_Date.hpp"
  17. #include "GUICINCLUDE:GUIC_Button.hpp"
  18. #include "GUICINCLUDE:GUIC_Register.hpp"
  19. #include "GUICINCLUDE:GUIC_FileString.hpp"
  20. #include "GUICINCLUDE:GUIC_FileExamine.hpp"
  21. #include "GUICINCLUDE:GUIC_PathString.hpp"
  22. #include "GUICINCLUDE:GUIC_SlidingInteger.hpp"
  23. #include "GUICINCLUDE:GUIC_Checkbox.hpp"
  24. #include "GUICINCLUDE:GUIC_Integer.hpp"
  25. #include "GUICINCLUDE:GUIC_Label.hpp"
  26. #include "GUICINCLUDE:GUIC_String.hpp"
  27. #include "GUICINCLUDE:GUIC_Screen.hpp"
  28. #include "GUICINCLUDE:GUIC_Application.hpp"
  29. #include "GUICINCLUDE:GUIC_Text.hpp"
  30. #include "GUICINCLUDE:GUIC_Frame.hpp"
  31. #include "GUICINCLUDE:GUIC_Cycle.hpp"
  32. #include "GUICINCLUDE:GUIC_Radio.hpp"
  33. #include "GUICINCLUDE:GUIC_GGFXPicture.hpp"
  34. #include "GUICINCLUDE:GUIC_BorderProp.hpp"
  35.  
  36. #include "GalleryWindow.hpp"
  37. #include "ManagerWindow.hpp"
  38. #include "StatusWindow.hpp"
  39. #include "PictureWindow.hpp"
  40. #include "ThumbnailWindow.hpp"
  41.  
  42. /*********************************************************************************************************/
  43.  
  44. static class GalleryEntryC : public GUIC_ObjectC
  45.     {
  46.     public:
  47.         GalleryEntryC            (STRPTR f, LONG s, LONG d, LONG m, LONG y, BOOL i, STRPTR p, STRPTR p2)
  48.             { 
  49.             fileName=f; 
  50.             size=s; 
  51.             day=d; 
  52.             month=m; 
  53.             year=y; 
  54.             isDirectory = i;
  55.             pattern = p;
  56.             pattern2 = p2;
  57.             }
  58.         LONG        compare    (GUIC_ObjectC &o)
  59.             {
  60.             // First we must convert the argument to what it really is:
  61.             GalleryEntryC *g = (GalleryEntryC *)&o; 
  62.             return Stricmp(this->fileName, g->fileName); // Just compare the two file names    
  63.             }
  64.         VOID        print        (VOID)
  65.             { 
  66.             cout << fileName << " -> " << size << endl; 
  67.             }
  68.         STRPTR    getClass    (VOID)
  69.             {
  70.             return "GalleryEntryC"
  71.             }
  72.         
  73.         STRING     fileName, pattern, pattern2;
  74.         LONG     day, month, year;
  75.         LONG     size;
  76.         BOOL     isDirectory;
  77.     protected:
  78.         VOID        cleanUp    (VOID)
  79.             {
  80.             }
  81.     };
  82.     
  83. /*********************************************************************************************************/
  84.     
  85. GalleryWindowC::GalleryWindowC                        (GUIC_ApplicationC &a, GUIC_ScreenC &s) : GUIC_WindowC (-1,-1,48,24)
  86. {
  87.     totalFiles    = 0;
  88.     actualFiles    = 0;
  89.     screen        = &s;
  90.     app                = &a;
  91.     pWindow        = 0;
  92.     sWindow        = 0;
  93.     tWindow        = 0;
  94.     mWindow    = 0;
  95.     
  96.     // Register erstellen
  97.     reg = new GUIC_RegisterC            (1,1,46,19,5);
  98.     
  99.     reg -> setName(1, "Global");
  100.     reg -> setName(2, "Tables");
  101.     reg -> setName(3, "HTML");
  102.     reg -> setName(4, "Thumb");
  103.     reg -> setName(5, "Manager");
  104.     
  105.     reg -> setShortcut ('g');
  106.         
  107.     app -> addPrefs("Register", reg);
  108.  
  109.     add ( reg );
  110.  
  111.  
  112.     // Erstes Register (GLOBAL)
  113.     dirLabel                = new GUIC_LabelC            ( 0, 2,10,2,"_Directory:");
  114.     patternLabel        = new GUIC_LabelC            ( 0, 4,10,2,"Pattern _1:");
  115.     pattern2Label        = new GUIC_LabelC            ( 0, 6,10,2,"Pattern _2:");
  116.     baseNameLabel    = new GUIC_LabelC            ( 0, 9,30,2,"_Base name for HTML files:");
  117.     hideLabel            = new GUIC_LabelC            ( 0,12,35,2,"Set _Hide flag for thumbnails:");
  118.     directory                = new GUIC_PathStringC    (11, 2,33,2,"");
  119.     pattern                = new GUIC_FileStringC        (11, 4,33,2,"");
  120.     pattern2                = new GUIC_FileStringC        (11, 6,33,2,"");
  121.     baseName            = new GUIC_StringC            (31, 9,13,2,"index");
  122.     hideFlag                = new GUIC_CheckboxC        (41,12, 3,2, FALSE);
  123.     
  124.     pattern        -> setFilter(GUIC_PictureFile);
  125.  
  126.     directory        -> setHelp("Directory for the first index file.");
  127.     pattern        -> setHelp("Background pattern in HTML pages.");
  128.     pattern2        -> setHelp("Background pattern in galleries.");
  129.     baseName    -> setHelp("Enter base file name without a suffix."),
  130.     hideFlag        -> setHelp("Sets the H flag for your file system.");
  131.     
  132.     directory        -> setShortcut('d');
  133.     pattern        -> setShortcut('1');
  134.     pattern2        -> setShortcut('2');
  135.     baseName    -> setShortcut('b');
  136.     hideFlag        -> setShortcut('h');
  137.     
  138.     app->addPrefs("StartDirectory"            , directory);
  139.     app->addPrefs("BackgroundPattern"     , pattern);
  140.     app->addPrefs("BackgroundPattern2"    , pattern2);
  141.     app->addPrefs("BaseName"                    , baseName);
  142.     app->addPrefs("HideFlag"                        , hideFlag);
  143.     
  144.     reg->add(1, dirLabel);
  145.     reg->add(1, patternLabel);
  146.     reg->add(1, pattern2Label);
  147.     reg->add(1, directory);
  148.     reg->add(1, pattern);
  149.     reg->add(1, pattern2);
  150.     reg->add(1, baseNameLabel);
  151.     reg->add(1, baseName);
  152.     reg->add(1, hideLabel);
  153.     reg->add(1, hideFlag);
  154.  
  155.  
  156.     // Zweites Register (TABLES)
  157.     linesLabel                = new GUIC_LabelC                ( 0, 0,10,2,"_Lines:");
  158.     columnsLabel            = new GUIC_LabelC                ( 0, 2,10,2,"_Columns:");
  159.     sizeLabel                = new GUIC_LabelC                ( 0, 5,30,2,"Sh_ow size of picture:");
  160.     dateLabel                = new GUIC_LabelC                ( 0, 7,31,2,"Sho_w date of picture:");
  161.     clickLabel                = new GUIC_LabelC                ( 0,10,31,2,"_Use thumbnail picture as link:");
  162.     tableBorderLabel    = new GUIC_LabelC                ( 0,13,31,2,"Size of table's _border:");
  163.     lines                        = new GUIC_SlidingIntegerC    (11, 0,33,2,MINLINES,MAXLINES,DEFAULTLINES);
  164.     columns                    = new GUIC_SlidingIntegerC    (11, 2,33,2,MINCOLUMNS,MAXCOLUMNS,DEFAULTCOLUMNS);    
  165.     size                        = new GUIC_CheckboxC            (41, 5, 3,2,TRUE);
  166.     date                        = new GUIC_CheckboxC            (41, 7, 3,2,TRUE);
  167.     click                        = new GUIC_CheckboxC            (41,10, 3,2,FALSE);
  168.     tableBorder                = new GUIC_SlidingIntegerC    (30,13,14,2,MINTABLEBORDERSIZE, MAXTABLEBORDERSIZE, DEFTABLEBORDERSIZE);
  169.     
  170.     lines            ->setHelp("The number of lines per HTML table.");
  171.     columns        ->setHelp("The number of columns per HTML table.");
  172.     size            ->setHelp("Show picture's size in gallery?");
  173.     date            ->setHelp("Show picture's date in gallery?");
  174.     click            ->setHelp("Click on thumbnails to view picture?");
  175.     tableBorder    ->setHelp("Size of the border around the tables.");
  176.     
  177.     lines            ->setShortcut('l');
  178.     columns        ->setShortcut('c');
  179.     size            ->setShortcut('o');
  180.     date            ->setShortcut('w');
  181.     click            ->setShortcut('u');
  182.     tableBorder    ->setShortcut('b');
  183.  
  184.     app->addPrefs("NumberOfLines"            , lines);
  185.     app->addPrefs("NumberOfColumns"        , columns);
  186.     app->addPrefs("ShowSize"                    , size);
  187.     app->addPrefs("ShowDate"                    , date);
  188.     app->addPrefs("PictureAsLink"                , click);
  189.     app->addPrefs("TableFrameSize"            , tableBorder);
  190.  
  191.     reg->add (2, linesLabel );
  192.     reg->add (2, lines );
  193.     reg->add (2, columnsLabel );
  194.     reg->add (2, columns );
  195.     reg->add (2, sizeLabel );
  196.     reg->add (2, size );
  197.     reg->add (2, dateLabel );
  198.     reg->add (2, date );
  199.     reg->add (2, clickLabel );
  200.     reg->add (2, click );
  201.     reg->add (2, tableBorderLabel);
  202.     reg->add (2, tableBorder);
  203.     
  204.  
  205.     // Drittes Register (HTML)
  206.     noFramesLabel    = new GUIC_LabelC        ( 0, 5,35,2,"Don't _create frames:");
  207.     noFrames            = new GUIC_CheckboxC    (41, 5, 3,2,FALSE);
  208.     frameLabel            = new GUIC_LabelC        ( 0, 8,35,2,"Width of menu _frame (left frame):");
  209.     frame                    = new GUIC_IntegerC        (36, 8,8,2,MENUFRAMEWIDTH);
  210.  
  211.     noFrames    ->setHelp("Check if you don't want to have frames.");
  212.     noFrames    ->setShortcut('c');
  213.     
  214.     frame        ->setJustification(GUIC_Right);
  215.     frame        ->setHelp("No. of pixels for the left hand frame.");
  216.     frame        ->setShortcut('f');
  217.  
  218.     app->addPrefs("NoFrames"                    , noFrames);
  219.     app->addPrefs("MenuFrameWidth"        , frame);
  220.  
  221.     reg->add (3, noFramesLabel);
  222.     reg->add (3, noFrames);
  223.     reg->add (3, frameLabel );
  224.     reg->add (3, frame );
  225.     
  226.  
  227.     // Viertes Register (THUMBNAIL)
  228.     programLabel        = new GUIC_LabelC                ( 0, 0,44, 2,"System _call to create the thumbnails");
  229.     useGGFXLabel    = new GUIC_LabelC                ( 0, 5,40, 2,"Use guigf_x.library to create thumbnails:");
  230.     widthLabel            = new GUIC_LabelC                ( 0, 8,26, 2,"Max. _width of thumbnails:");
  231.     heightLabel            = new GUIC_LabelC                ( 0,10,26, 2,"Max. _height of thumbnails:");
  232.     createAllLabel    = new GUIC_LabelC                ( 0,13,40, 2,"Create _thumbnail for all pictures found:");
  233.     program                = new GUIC_StringC                ( 0, 2,44, 2,COMMAND);
  234.     useGGFX            = new GUIC_CheckboxC            (41, 5, 3, 2,FALSE);
  235.     width                    = new GUIC_SlidingIntegerC    (27, 8,17, 2,MINTHUMBNAILWIDTH,MAXTHUMBNAILWIDTH,DEFTHUMBNAILWIDTH);
  236.     height                    = new GUIC_SlidingIntegerC    (27,10,17, 2,MINTHUMBNAILHEIGHT,MAXTHUMBNAILHEIGHT,DEFTHUMBNAILHEIGHT);
  237.     createAll                = new GUIC_CheckboxC            (41,13, 3, 2,FALSE);
  238.  
  239.     width            -> setHelp("Maximum width for each thumbnail.");
  240.     height             -> setHelp("Maximum height for each thumbnail.");
  241.     createAll        -> setHelp("Do it even in directories with subdirs.");
  242.     useGGFX    -> setHelp("Use internal routines for thumbnail creation.");
  243.     
  244.     program        -> setMaxChars(128);
  245.     
  246.     program        -> setShortcut('c');
  247.     width            -> setShortcut('w');
  248.     height            -> setShortcut('h');
  249.     createAll     -> setShortcut('t');
  250.     useGGFX    -> setShortcut('x');
  251.     
  252.     app->addPrefs("ThumbnailWidth"            , width);
  253.     app->addPrefs("ThumbnailHeight"            , height);
  254.     app->addPrefs("SystemCall"                    , program);
  255.     app->addPrefs("CreateAllThumbnails"    , createAll);
  256.     app->addPrefs("UseGGFX"                    , useGGFX);
  257.     
  258.     reg->add (4, programLabel );
  259.     reg->add (4, program );
  260.     reg->add (4, useGGFXLabel );
  261.     reg->add (4, useGGFX );
  262.     reg->add (4, widthLabel );
  263.     reg->add (4, width );
  264.     reg->add (4, heightLabel );
  265.     reg->add (4, height );
  266.     reg->add (4, createAllLabel );
  267.     reg->add (4, createAll );
  268.  
  269.  
  270.     // Fünftes Register (MANAGER)
  271.     
  272.     sprintf(sDimensions, "%ld x %ld x %ld Bit", screenRequester.getWidth(), screenRequester.getHeight(), screenRequester.getDepth() );
  273.  
  274.     screenFrame    = new GUIC_FrameC        ( 0, 0,44,11,"Screenmode");
  275.     pubOrOwn        = new GUIC_RadioC        ( 2, 1, 3, 2, "Public Screen|Own Screen");
  276.     pubscreen        = new GUIC_StringC        (21, 1,21, 2, "Workbench");
  277.     screenButton    = new GUIC_ButtonC     (21, 3,21, 2,"Set S_creenmode");
  278.  
  279.     screenName     = new GUIC_TextC            ( 2, 6,41,2, screenRequester.getModeName() );
  280.     screenDims    = new GUIC_TextC            ( 2, 8,41,2, sDimensions);
  281.  
  282.     manager            = new GUIC_ButtonC        (0,12,44,2,"Switch to _manager mode of Gallery");
  283.     
  284.     manager            -> setHelp("Opens the manager window.");
  285.     screenButton    -> setHelp("Set the manager's screen mode.");
  286.     
  287.     screenName->setJustification(GUIC_Center);
  288.     screenName->setFrontPen(GUIC_ShinePen);
  289.  
  290.     screenDims->setBorder(FALSE);
  291.     screenDims->setJustification(GUIC_Center);
  292.     screenDims->setFrontPen(GUIC_ShinePen);
  293.     
  294.     app->addPrefs("PubScreenOrOwnScreen", pubOrOwn);
  295.     app->addPrefs("PubScreenName", pubscreen);
  296.     
  297.     reg->add(5, screenFrame);
  298.     reg->add(5, pubOrOwn);
  299.     reg->add(5, pubscreen);
  300.     reg->add(5, screenName);
  301.     reg->add(5, screenDims);
  302.     reg->add(5, screenButton);
  303.     reg->add(5, manager);
  304.     
  305.  
  306.     // Start und Quit Buttons
  307.     start                = new GUIC_ButtonC                ( 1,21,15,2,"_Start");
  308.     quit                    = new GUIC_ButtonC                (32,21,15,2,"_Quit");
  309.     
  310.     start        ->setHelp("Start the creation of the gallery.");
  311.     quit            ->setHelp("Quit the program.");
  312.     
  313.     start        ->setShortcut('s');
  314.     quit            ->setShortcut('q');
  315.  
  316.     add ( start );
  317.     add ( quit );
  318.  
  319.  
  320.     // Prefs für das Fenster 
  321.     app->addPrefs("Screenmode", screenRequester);
  322.     app->addPrefs("GalleryWindow", this);
  323.  
  324.     STRING t = app->getName();
  325.     t += " - (c) by ";
  326.     t += app->getAuthor();
  327.     setTitle(t);
  328.     
  329.     setGuideContext("GalleryWindow");
  330.     setHelp(TRUE);
  331.     
  332.     activate();
  333. }
  334. GalleryWindowC::~GalleryWindowC                        (VOID)
  335. {
  336.     cleanUp();
  337. }
  338.  
  339. /*********************************************************************************************************/
  340.  
  341. VOID         GalleryWindowC::createHTML                (GUIC_ListC &fileList, STRPTR pattern, BOOL showDate, LONG tableBorderSize, STRPTR baseName, BOOL noFrames)
  342. {
  343.     GalleryEntryC *key = (GalleryEntryC *)fileList.objectAt(1);
  344.     GUIC_FileExamineC firstFile(key->fileName);
  345.  
  346.     STRPTR currentDir = firstFile.getPathPart(), st = 0;
  347.     GUIC_SystemC::reallocString(&st, baseName, ".html");
  348.     GUIC_FileC indexFile(currentDir, st, GUIC_Write);
  349.     
  350.     GUIC_FileExamineC directoryName(currentDir);
  351.     STRPTR filenote = directoryName.getFilenote();
  352.     if (filenote && !strcmp(filenote, "") ) filenote = 0;
  353.  
  354.     STRING titleString = directoryName.getFilePart();
  355.     if (titleString == STRING("") ) titleString = directoryName.getName();
  356.  
  357.     indexFile.writeLn("<HTML>");
  358.     indexFile.writeLn("<HEAD>");
  359.     indexFile.write("<TITLE> "); indexFile.write(filenote ? filenote : titleString); indexFile.writeLn(" </TITLE>");
  360.     indexFile.writeLn("</HEAD>");
  361.     indexFile.write("<BODY");
  362.     if (pattern)
  363.         {
  364.         indexFile.write(" Background=\"");
  365.         indexFile.write(pattern);
  366.         indexFile.write("\"");
  367.         }
  368.     indexFile.writeLn(">");
  369.     indexFile.write("<CENTER><H1>"); indexFile.write(filenote ? filenote : titleString); indexFile.writeLn("</H1>");
  370.     indexFile.writeLn("<HR><BR><BR>");
  371.     
  372.     // Create the table of galleries
  373.     
  374.     indexFile.write("<TABLE Border=");
  375.     indexFile.write(tableBorderSize);
  376.     indexFile.writeLn(" CellSpacing=4 CellPadding=4>");
  377.     indexFile.writeLn("<TR> <TH BGCOLOR=\"A99A99\"> <CENTER> <H3> Gallery Name </H3> </TH> <TH BGCOLOR=\"A99A99\"> <CENTER> <H3> Entries </H3> </TH> </TR>");
  378.     
  379.     for (LONG i=1; i<=fileList.length(); i++)
  380.         {
  381.         key = (GalleryEntryC *)fileList.objectAt(i);
  382.         GUIC_FileExamineC file (key->fileName);
  383.         STRPTR filenote = file.getFilenote();
  384.         if (filenote && !strcmp(filenote, "")) filenote=0;
  385.         
  386.         indexFile.write("<TR> <TD BGCOLOR=\"BBBBBB\"> <CENTER> <A HREF=\"");
  387.         indexFile.write(file.getFilePart());
  388.         indexFile.write("/");
  389.         indexFile.write(baseName);
  390.         
  391.         if (noFrames) indexFile.write("1");
  392.         
  393.         indexFile.write(".html\"");
  394.         indexFile.write("> ");
  395.         indexFile.write(filenote ? filenote : file.getFilePart());
  396.         indexFile.write(" </A> </TD> <TD BGCOLOR=\"BBBBBB\"> <CENTER> ");
  397.         indexFile.write(key->size);
  398.         indexFile.writeLn(" </TD> </TR>");
  399.         }
  400.  
  401.     indexFile.writeLn("</TABLE>");
  402.  
  403.     indexFile.write("<BR> <IMG SRC=internal-gopher-menu> <A HREF=\"../");
  404.     indexFile.write(baseName);
  405.     indexFile.writeLn(".html\" TARGET=_top> up </A> <BR>");
  406.  
  407.     indexFile.writeLn("<HR>");
  408.     indexFile.writeLn(COPYRIGHT);
  409.     indexFile.writeLn("</BODY>");
  410.     indexFile.writeLn("</HTML>");
  411. }
  412. VOID         GalleryWindowC::createGallery            (GUIC_ListC &fileList, STRPTR pattern, STRPTR pattern2, LONG linesInTable, LONG columnsInTable, BOOL picClick, BOOL showSize, BOOL showDate, LONG menuFrameWidth, LONG thumbnailWidth, LONG thumbnailHeight, LONG tableBorderSize, STRPTR baseName, BOOL noFrames)
  413. {
  414.     BOOL        setHideFlag    = hideFlag->get();
  415.     ULONG     pictureFiles    = fileList.length();
  416.     
  417.     GalleryEntryC *key = (GalleryEntryC *)fileList.objectAt(1);
  418.     GUIC_FileExamineC firstFile(key->fileName);
  419.     STRING currentDir = firstFile.getPathPart();
  420.     
  421.     ldiv_t d = ldiv ( pictureFiles, columnsInTable );
  422.     LONG lines = d.quot;
  423.     if (d.rem) lines++;
  424.     
  425.     d = ldiv (lines, linesInTable);
  426.     LONG galleries = d.quot;
  427.     if (d.rem) galleries++;
  428.  
  429.     GUIC_FileExamineC directoryName(currentDir);
  430.     STRPTR filenote = directoryName.getFilenote();
  431.     if (filenote && !strcmp(filenote, "")) filenote=0;
  432.     
  433.     if (! noFrames) // Create frames and overview
  434.         {
  435.         // Create the index file with the frames
  436.         STRPTR st = 0;
  437.         GUIC_SystemC::reallocString(&st, baseName, ".html");
  438.         GUIC_FileC gallery(currentDir, st, GUIC_Write);
  439.         
  440.         gallery.write("<TITLE>Gallery '");
  441.         gallery.write(filenote ? filenote : directoryName.getFilePart());
  442.         gallery.writeLn("'</TITLE>");
  443.         gallery.write("<FRAMESET COLS=");
  444.         gallery.write(menuFrameWidth);
  445.         gallery.writeLn(",*>");
  446.         gallery.write("<FRAME NAME=F1 SRC=\"");
  447.         gallery.write(baseName);
  448.         gallery.writeLn("0.html\" MarginHeight=0 MarginWidth=0 Scrolling=\"auto\" FrameBorder=0>");
  449.         gallery.write("<FRAME NAME=F2 SRC=\"");
  450.         gallery.write(baseName);
  451.         gallery.writeLn("1.html\" MarginHeight=0 MarginWidth=0 Scrolling=\"auto\" FrameBorder=0>");
  452.         gallery.writeLn("</FRAMESET>");
  453.     
  454.         // now create the overview over the galleries
  455.         GUIC_SystemC::reallocString(&st, baseName, "0.html");
  456.         GUIC_FileC overview (currentDir, st, GUIC_Write);
  457.     
  458.         overview.writeLn("<HTML>");
  459.         overview.write("<BODY");
  460.         if (pattern)
  461.             {
  462.             overview.write(" Background=\"");
  463.             overview.write(pattern);
  464.             overview.write("\"");
  465.             }
  466.         overview.writeLn(">");
  467.         overview.write("<H2 ALIGN=Center> Gallery </H2><BR><UL>");
  468.         for (LONG i=1; i<=galleries; i++)
  469.             {
  470.             overview.write("<LI><A HREF=\"");
  471.             overview.write(baseName);
  472.             overview.write(i);
  473.             overview.write(".html\" TARGET=F2>Part ");
  474.             overview.write(i);
  475.             overview.writeLn("</A> <BR>");
  476.             }
  477.         
  478.         overview.write("</UL><BR> <BR> <IMG SRC=internal-gopher-menu> <A HREF=\"../");
  479.         overview.write(baseName);
  480.         overview.writeLn(".html\" TARGET=_top> up </A>");
  481.         overview.writeLn("</BODY>\n</HTML>");
  482.         }
  483.  
  484.     // create each gallery
  485.     LONG count = 0;
  486.     for (LONG i=1; i<=galleries; i++)
  487.         {
  488.         CHAR filename[256];
  489.         sprintf(filename, "%s%ld.html", baseName, i);
  490.         GUIC_FileC indexFile(currentDir, filename, GUIC_Write);
  491.  
  492.         // write head and title    
  493.         indexFile.writeLn("<HTML>");
  494.         indexFile.writeLn("<HEAD>");
  495.     
  496.         indexFile.write("<TITLE> "); indexFile.write(filenote ? filenote : directoryName.getFilePart());    indexFile.writeLn(" </TITLE>");
  497.         indexFile.writeLn("</HEAD>");
  498.         indexFile.write("<BODY");
  499.  
  500.         if (pattern)
  501.             {
  502.             indexFile.write(" Background=\"");
  503.             indexFile.write(pattern2);
  504.             indexFile.write("\"");
  505.             }
  506.         indexFile.writeLn(">");
  507.         
  508.         indexFile.write("<CENTER><H2>"); 
  509.         indexFile.write(filenote ? filenote : directoryName.getFilePart()); 
  510.         indexFile.write("</H2> (Part ");
  511.         indexFile.write(i);
  512.         indexFile.write(" of ");
  513.         indexFile.write(galleries);
  514.         indexFile.writeLn(")<BR>");
  515.  
  516.         indexFile.writeLn("<HR>");
  517.         indexFile.write("<TABLE Border=");
  518.         indexFile.write(tableBorderSize);
  519.         indexFile.writeLn(" CellSpacing=4 CellPadding=4>");
  520.         
  521.         LONG boundary = count + columnsInTable*linesInTable;
  522.         if (boundary>pictureFiles) boundary = pictureFiles;
  523.         
  524.         for (LONG j=count; j<boundary; j++)
  525.             {
  526.             key = (GalleryEntryC *)fileList.objectAt(j+1);
  527.             GUIC_FileExamineC file(key->fileName);
  528.             STRING thumbName = "";
  529.             
  530.             // Create the thumbnail now            
  531.             try
  532.                 {
  533.                 thumbName = makeThumbnail(file, thumbnailWidth, thumbnailHeight, useGGFX->get() );
  534.                 GUIC_FileExamineC thumb (thumbName);
  535.                 thumbName = thumb.getFilePart();
  536.                 
  537.                 // Set the hide flag if requested by the user
  538.                 if (setHideFlag) thumb.setHidden(TRUE);
  539.                 }
  540.             catch (GUIC_SystemX &e) { GalleryEntryC *s = new GalleryEntryC(key->fileName,0,0,0,0, FALSE, "", ""); errorList.addTail(*s); }
  541.  
  542.             // Check if there are enough entries per line in the table
  543.             if (count++ % columnsInTable == 0) indexFile.write("<TR> ");
  544.             
  545.             // Now that count ist increased, update the status window
  546.             sWindow->setPercent ( (++actualFiles * 100) / totalFiles );
  547.  
  548.             // write the picture data
  549.             indexFile.write("<TD BGCOLOR=\"777777\"> <CENTER>");
  550.             
  551.             if (picClick)
  552.                 {
  553.                 indexFile.write("<A HREF=\"");
  554.                 indexFile.write(file.getFilePart());
  555.                 indexFile.write("\"> <IMG SRC=\"");
  556.                 indexFile.write(thumbName);
  557.                 indexFile.write("\" ALT=Thumbnail BORDER=0> <BR>");
  558.                 }
  559.             else
  560.                 {
  561.                 indexFile.write("<IMG SRC=\"");
  562.                 indexFile.write(thumbName);
  563.                 indexFile.write("\" ALT=Thumbnail> <BR>");
  564.                 indexFile.write("<A HREF=\"");
  565.                 indexFile.write(file.getFilePart());
  566.                 indexFile.write("\">");
  567.                 }
  568.                 
  569.             indexFile.write(file.getFilePart());
  570.             indexFile.write(" </A>");
  571.             
  572.             if (showSize)
  573.                 {
  574.                 indexFile.write("<BR> Size: ");
  575.                 indexFile.write(key->size);
  576.                 }
  577.                 
  578.             if (showDate)
  579.                 {
  580.                 indexFile.write("<BR> Date: ");
  581.                 indexFile.write(key->day);
  582.                 indexFile.write(".");
  583.                 indexFile.write(key->month);
  584.                 indexFile.write(".");
  585.                 indexFile.write(key->year);
  586.                 }
  587.             indexFile.writeLn("</TD>");
  588.             }
  589.             
  590.         indexFile.writeLn("</TABLE>");
  591.         
  592.         if (noFrames && galleries>1) // then create jump points
  593.             {
  594.             indexFile.writeLn("<BR>");
  595.             
  596.             if (i > 1) 
  597.                 {
  598.                 indexFile.write("<A HREF=\"");
  599.                 indexFile.write(baseName);
  600.                 indexFile.write(i-1);
  601.                 indexFile.writeLn(".html\">[prev] </A>");
  602.                 }
  603.             else indexFile.writeLn("[prev] ");
  604.             
  605.             for (LONG gal=1; gal<=galleries; gal++)
  606.                 {
  607.                 if (i != gal)
  608.                     {
  609.                     indexFile.write(" <A HREF=\"");
  610.                     indexFile.write(baseName);
  611.                     indexFile.write(gal);
  612.                     indexFile.write(".html\">");
  613.                     indexFile.write(gal);
  614.                     indexFile.writeLn("</A> ");
  615.                     }
  616.                 else 
  617.                     {
  618.                     indexFile.write(" ");
  619.                     indexFile.write(gal);
  620.                     indexFile.writeLn(" ");
  621.                     }
  622.                 }
  623.             
  624.             if (i < galleries) 
  625.                 {
  626.                 indexFile.write("<A HREF=\"");
  627.                 indexFile.write(baseName);
  628.                 indexFile.write(i+1);
  629.                 indexFile.writeLn(".html\"> [next]</A>");
  630.                 }
  631.             else indexFile.writeLn("[next]");
  632.             
  633.             indexFile.write("<BR> <IMG SRC=internal-gopher-menu> <A HREF=\"../");
  634.             indexFile.write(baseName);
  635.             indexFile.writeLn(".html\"> up </A>");
  636.  
  637.             }
  638.  
  639.         indexFile.writeLn("<HR>");
  640.         indexFile.writeLn(COPYRIGHT);
  641.         indexFile.writeLn("</BODY>");
  642.         indexFile.writeLn("</HTML>");
  643.         }
  644. }
  645. BOOL        GalleryWindowC::action                        (GUIC_EventC &e)
  646. {
  647.     static BOOL screenSet = FALSE;
  648.     
  649.     switch (e.id)
  650.         {
  651.         case GUIC_GadgetEvent:
  652.             if (e.gadget == (GUIC_GadgetC *)start)
  653.                 {
  654.                 if (! strcmp(directory->get(), "") )
  655.                     {
  656.                     GUIC_ErrorC err("You must at least enter a directory name!");
  657.                     err.request(this);
  658.                     }
  659.                 else 
  660.                     {
  661.                     sleep();
  662.                     
  663.                     if (sWindow == 0) sWindow = new StatusWindowC(*app, *screen);
  664.                     screen->add(sWindow);
  665.                     sWindow->sleep();
  666.                     
  667.                     try 
  668.                         {
  669.                         sWindow->setMessage ( "Scanning for picture files." );
  670.                         totalFiles     = scanDirectory ( directory->get(), pattern->get(), pattern2->get(), createAll->get() );
  671.                         actualFiles    = 0;
  672.                         
  673. //                        sWindow->setMessage ( "Sorting file list." );
  674. //                        fileList.sort();
  675.                         
  676.                         CHAR st [64];
  677.                         sprintf(st, "Processing %ld files.", totalFiles);
  678.                         sWindow->setMessage ( st );
  679.                         generateGallery();
  680.                         
  681.                         // Nachsehen, ob es Fehlermeldungen gab:
  682.                         if (errorList.length())
  683.                             {
  684.                             GUIC_MessageC err ("Some errors have occured while scanning/creating thumbnails:", "Print|Forget");
  685.                             if (1 == err.request(this))
  686.                                 {
  687.                                 GUIC_SystemC::openConsole();
  688.                                 cerr << "The following files could not be converted to a thumbnail:" << endl;
  689.                                 while (errorList.length())
  690.                                     {
  691.                                     GalleryEntryC *s = (GalleryEntryC *)errorList.remove(1);
  692.                                     cerr << "- " << s->fileName << endl;
  693.                                     delete s;
  694.                                     }
  695.                                 cerr << "Please check them and run 'Gallery' again." << endl;
  696.                                 }
  697.                             else 
  698.                                 {
  699.                                 while (errorList.length()) delete (GalleryEntryC*) errorList.remove(1);
  700.                                 }
  701.                             }
  702.                         }
  703.                     catch (GUIC_Exception &x) { GUIC_ErrorC e("Exception caught:", x.getMessage() ); e.request(this); }
  704.                     
  705.                     // File Liste wieder löschen
  706.                     while ( fileList.length() ) delete (GalleryEntryC *)fileList.remove(1);
  707.                     
  708.                     sWindow->waken();
  709.                     screen->remove(sWindow);
  710.                     
  711.                     waken();
  712.                     }
  713.                 return TRUE;
  714.                 }
  715.             else if (e.gadget == (GUIC_GadgetC *)quit) 
  716.                 {
  717.                 dispose();
  718.                 return TRUE;
  719.                 }
  720.             else if (e.gadget == (GUIC_GadgetC *)manager)
  721.                 {
  722.                 if (mWindow == 0) 
  723.                     { 
  724.                     sleep(); 
  725.                     pWindow        = new PictureWindowC        (*app, *screen);
  726.                     tWindow        = new ThumbnailWindowC    (*app, *screen);
  727.                     mWindow    = new ManagerWindowC    (*app, *screen); 
  728.                     waken(); 
  729.                     }
  730.                 screen->remove(this);
  731.                 mWindow->setWindows            ( *tWindow, *pWindow );
  732.                 mWindow->setThumbnailDim    ( width->get(), height->get() );
  733.                 if (! screenSet)
  734.                     {
  735.                     if (pubOrOwn->getActive() == 1) screen->set(pubscreen->get()); else screen->set(screenRequester);
  736.                     screenSet = TRUE;
  737.                     }
  738.                 screen->add(pWindow);
  739.                 screen->add(tWindow);
  740.                 screen->add(mWindow);
  741.                 return TRUE;
  742.                 }
  743.             else if (e.gadget == (GUIC_GadgetC *)screenButton)
  744.                 {
  745.                 if (screenRequester.request(this) ) 
  746.                     {
  747.                     screen->set(screenRequester);
  748.                     sprintf(sDimensions, "%ld x %ld x %ld Bit", screenRequester.getWidth(), screenRequester.getHeight(), screenRequester.getDepth() );
  749.                     screenName->set(screenRequester.getModeName());
  750.                     screenDims->set(sDimensions);
  751.                     screenSet = TRUE;
  752.                     }
  753.                 return TRUE;
  754.                 }
  755.             else if (e.gadget == (GUIC_GadgetC *)pubOrOwn)
  756.                 {
  757.                 if (pubOrOwn->getActive() == 1) 
  758.                     {
  759.                     screenButton->disable(); 
  760.                     pubscreen->enable();
  761.                     screen->set(pubscreen->get()); 
  762.                     screenSet = TRUE;
  763.                     }
  764.                 else 
  765.                     {
  766.                     pubscreen->disable();
  767.                     screenButton->enable();
  768.                     screen->set(screenRequester);
  769.                     screenSet = TRUE;
  770.                     }
  771.                 return TRUE;
  772.                 }
  773.             else if (e.gadget == (GUIC_GadgetC *)pubscreen)
  774.                 {
  775.                 screen->set(pubscreen->get());
  776.                 screenSet = TRUE;
  777.                 return TRUE;
  778.                 }
  779.             else if (e.gadget == (GUIC_GadgetC *)useGGFX)
  780.                 {
  781.                 if (useGGFX->get()) program->disable(); else program->enable();
  782.                 return TRUE;
  783.                 }
  784.             break;
  785.         case GUIC_OpenWindow:
  786.             sprintf(sDimensions, "%ld x %ld x %ld Bit", screenRequester.getWidth(), screenRequester.getHeight(), screenRequester.getDepth() );
  787.             screenName->set(screenRequester.getModeName());
  788.             screenDims->set(sDimensions);
  789.             if (pubOrOwn->getActive() == 1) screenButton->disable(); else pubscreen->disable();
  790.             if (useGGFX->get() ) program->disable();
  791.             return TRUE;
  792.             break;
  793.         case GUIC_CloseWindow: 
  794.             
  795.             return FALSE;
  796.             break;
  797.         default:
  798.             cerr << "Got an event: " << e.id << endl;
  799.         }
  800.     
  801.     return FALSE;
  802. }
  803. ULONG    GalleryWindowC::scanDirectory            (STRPTR startDir, STRPTR pattern, STRPTR pattern2, BOOL allFiles)
  804. {
  805.     GUIC_ListC subdirList;
  806.     
  807.     GalleryEntryC *key = 0;
  808.     GUIC_FileExamineC *filex = 0;
  809.     LONG entries = 0;
  810.  
  811.     GUIC_FileExamineC *examine = new GUIC_FileExamineC(startDir);
  812.     if (!examine->isDirectory()) throw GUIC_SystemX("Error in method scanDirectory (directory name expected).");
  813.     STRING dirName        = examine->getName();
  814.     STRING message    = "Scanned pictures in "; message += examine->getFilePart();
  815.     delete examine; examine=0;
  816.  
  817.     GUIC_DirectoryExamineC *direx= new GUIC_DirectoryExamineC(dirName);
  818.     BOOL hasSubDirs = direx->hasSubdirectory();
  819.     if (!hasSubDirs) direx->setFilter(FILEFILTER);
  820.     
  821.     try
  822.         {
  823.         while ( (filex = direx->examineNext()) )
  824.             {
  825.             STRING fileName  = filex->getName();
  826.             GUIC_DateC *date = filex->getDate();
  827.             
  828.             if (filex->isDirectory())
  829.                 {
  830.                 STRING newPattern = "../"; newPattern += pattern;
  831.                 STRING newPattern2 = "../"; newPattern2 += pattern2;
  832.                 ULONG entriesInDir = scanDirectory ((STRPTR)fileName, (STRPTR)newPattern, (STRPTR)newPattern2, allFiles);
  833.                 if (entriesInDir)
  834.                     {
  835.                     entries+=entriesInDir;
  836.                     GUIC_DirectoryExamineC d(fileName);
  837.                     key = new GalleryEntryC(fileName, entriesInDir, 0, 0, 0, TRUE, newPattern, newPattern2);
  838.                     if (! d.hasSubdirectory() )
  839.                         {
  840.                         fileList.addSorted(key);
  841.                         subdirList.addSorted( new GalleryEntryC(fileName, entriesInDir, 0, 0, 0, TRUE, newPattern, newPattern2) );
  842.                         }
  843.                     else 
  844.                         {
  845.                         subdirList.addSorted(key);
  846.                         }
  847.                     }
  848.                 }
  849.             else if (! hasSubDirs && (fileName.right(5) != STRING("_.jpg") ) )
  850.                 {
  851.                 key = new GalleryEntryC(fileName, filex->getSize(), date->getDay(), date->getMonth(), date->getYear(), FALSE, "", "");
  852.                 fileList.addSorted(*key);
  853.                 entries++;
  854.                 }
  855.             else if (allFiles && hasSubDirs && (fileName.right(5) != STRING("_.jpg") ) )
  856.                 {
  857.                 if (filex->getFileType() == GUIC_PictureFile)
  858.                     {
  859.                     STRING t = sWindow->getMessage();
  860.                     CHAR st[64];
  861.                     sprintf(st, "Generating thumbnail for '%s'", filex->getFilePart() );
  862.                     sWindow->setMessage(st);
  863.                     makeThumbnail(*filex, width->get(), height->get(), useGGFX->get() );
  864.                     sWindow->setMessage(t);
  865.                     }
  866.                 }
  867.             }
  868.         }
  869.     catch (GUIC_SystemX &e) { cerr << "Exception caught while processing directory '" << direx->getName() << "': " << e.getMessage() << endl; }
  870.     delete direx;direx=0; /* Damit der lock auf das Verzeichnis freigegeben wird ! */
  871.  
  872.     if (subdirList.length() ) // Generiere die Indexfiles für die Gallerien
  873.         {
  874.         if (subdirList.length()) createHTML (subdirList, pattern, date->get(), tableBorder->get(), baseName->get(), noFrames->get() );
  875.         while (subdirList.length()) delete (GalleryEntryC *) subdirList.remove(1);
  876.         }
  877.  
  878.     // Dem Benutzer melden, wie viele Bilder gesammelt worden sind
  879.     sWindow->setMessage ( message );
  880.     
  881.     return entries;
  882. }
  883. VOID        GalleryWindowC::generateGallery        (VOID)
  884. {
  885.     GalleryEntryC *entry = (GalleryEntryC*) fileList.objectAt(1);
  886.     if (! entry->isDirectory) // dann wurde nur ein einzelnes Verzeichnis eingescannt
  887.         {
  888.         createGallery ( fileList, pattern->get(), pattern2->get(), lines->get(), columns->get(), click->get(), size->get(), date->get(), frame->get(), width->get(), height->get(), tableBorder->get(), baseName->get(), noFrames->get() );
  889.         return;
  890.         }
  891.         
  892.     while ( fileList.length() )
  893.         {
  894.         entry = (GalleryEntryC*) fileList.remove(1);
  895.         if (entry->isDirectory)
  896.             {
  897.             GUIC_ListC list;
  898.             for (LONG i=1; i<=entry->size; i++) list.addTail ( fileList.remove(1) );
  899.             createGallery ( list, (STRPTR)entry->pattern, (STRPTR)entry->pattern2, lines->get(), columns->get(), click->get(), size->get(), date->get(), frame->get(), width->get(), height->get(), tableBorder->get(), baseName->get(), noFrames->get() );
  900.             while (list.length()) delete (GalleryEntryC*) list.remove(1);
  901.             delete entry;
  902.             }
  903.         else 
  904.             {
  905.             delete entry;
  906.             throw GUIC_Exception ( "Error in method generateGallery():\nExpected a directory name, not a file '", entry->fileName, "'");
  907.             }
  908.         }
  909. }
  910. STRING     GalleryWindowC::makeThumbnail        (GUIC_FileExamineC &file, LONG thumbnailWidth, LONG thumbnailHeight, BOOL useGGFX)
  911. {
  912.     STRING fileName = file.getName();
  913.  
  914.     LONG i = fileName.length();
  915.     while (--i) if (fileName[i] == '.') break;
  916.  
  917.     STRING thumbName = fileName.left(i);
  918.     thumbName+="_.jpg";
  919.  
  920.     try
  921.         {
  922.         GUIC_FileExamineC f(thumbName);
  923.         if (f.newer(file)) return thumbName;
  924.         }
  925.     catch (GUIC_SystemX &e) { }
  926.  
  927.     STRING oldMessage     = sWindow->getMessage();
  928.     STRING newMessage    = "Creating thumbnail for "; newMessage += file.getFilePart();
  929.     
  930.     sWindow->setMessage(newMessage);
  931.     
  932.     if (useGGFX)
  933.         {
  934.         try
  935.             {
  936.             GUIC_GGFXPictureC pic (fileName);
  937.             pic.scaleToBox(thumbnailWidth, thumbnailHeight);
  938.             pic.saveJPEG(thumbName, 90);
  939.             }
  940.         catch (GUIC_Exception &e) {}
  941.         }
  942.     else
  943.         {
  944.         CHAR p[2048];
  945.         sprintf ( p, program->get(), (STRPTR)fileName, (STRPTR)thumbName, thumbnailWidth, thumbnailHeight);
  946.         GUIC_SystemC::runProgram(p, 100000);
  947.         }
  948.     
  949.     sWindow->setMessage(oldMessage);
  950.     
  951.     return thumbName;
  952. }
  953. STRPTR    GalleryWindowC::getClass                    (VOID)
  954. {
  955.     return "GalleryWindowC";
  956. }
  957.  
  958. /*********************************************************************************************************/
  959.  
  960. VOID        GalleryWindowC::cleanUp                    (VOID)
  961. {
  962.     while ( fileList.length() )     delete (GalleryEntryC *)fileList.remove(1);
  963.     while ( errorList.length() )    delete (GalleryEntryC *)errorList.remove(1);
  964.  
  965.     delete reg;
  966.     delete dirLabel;
  967.     delete directory;
  968.     delete patternLabel;
  969.     delete pattern;
  970.     delete pattern2Label;
  971.     delete pattern2;
  972.     delete linesLabel;
  973.     delete lines;
  974.     delete columnsLabel;
  975.     delete columns;
  976.     delete clickLabel;
  977.     delete click;
  978.     delete sizeLabel;
  979.     delete size;
  980.     delete dateLabel;
  981.     delete date;
  982.     delete frameLabel;
  983.     delete frame;
  984.     delete widthLabel;
  985.     delete width;
  986.     delete heightLabel;
  987.     delete height;
  988.     delete tableBorderLabel;
  989.     delete tableBorder;
  990.     delete start;
  991.     delete quit;
  992.     delete createAllLabel;
  993.     delete createAll;
  994.     delete programLabel;
  995.     delete program;
  996.     delete baseNameLabel;
  997.     delete baseName;
  998.     delete manager;
  999.     delete noFramesLabel;
  1000.     delete noFrames;
  1001.     delete screenFrame;
  1002.     delete pubOrOwn;
  1003.     delete pubscreen;
  1004.     delete screenName;
  1005.     delete screenDims;
  1006.     delete screenButton;
  1007.     delete useGGFXLabel;
  1008.     delete useGGFX;
  1009.     delete hideLabel;
  1010.     delete hideFlag;
  1011.     
  1012.     if (mWindow)        delete mWindow;
  1013.     if (pWindow)         delete pWindow;
  1014.     if (tWindow)        delete tWindow;
  1015.     if (sWindow)         delete sWindow;
  1016. }
  1017.  
  1018.